package com.gopay.common.manager.ptbank.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.gopay.common.constants.ptbank.HfBankConstants.BankServiceState;
import com.gopay.common.dao.ptbank.GsrtBankServiceInfoDao;
import com.gopay.common.domain.ptbank.GsrtBankServiceInfo;
import com.gopay.common.manager.ptbank.GsrtBankServiceInfoManager;

/**
 * G商融通银行服务表
 * GsrtBankServiceInfoManagerImpl.java
 * 2016年4月27日
 * @author donghuijun
 *  www.gopay.com.cn Inc.All rights reserved.
 */
@Service("gsrtBankServiceInfoManager")
public class GsrtBankServiceInfoManagerImpl implements GsrtBankServiceInfoManager {
	@Resource(name = "gsrtBankServiceInfoDao")
    private GsrtBankServiceInfoDao gsrtBankServiceInfoDao;

	@Override
	public GsrtBankServiceInfo findServiceInfoById(GsrtBankServiceInfo gsrtBankServiceInfo) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		
		StringBuffer hql = new StringBuffer("from GsrtBankServiceInfo g where 1=1 ");
		if(null != gsrtBankServiceInfo.getBankSuperviseId()){
			hql.append("and g.bankSuperviseId=:bankSuperviseId ");
			paramMap.put("bankSuperviseId", gsrtBankServiceInfo.getBankSuperviseId());
		}	
		if(StringUtils.isNotEmpty(gsrtBankServiceInfo.getBankServiceId())){
			hql.append("and g.bankServiceId=:bankServiceId ");
			paramMap.put("bankServiceId", gsrtBankServiceInfo.getBankServiceId());
		}	
		if(StringUtils.isNotEmpty(gsrtBankServiceInfo.getBankServiceUrl())){
			hql.append("and g.bankServiceUrl=:bankServiceUrl ");
			paramMap.put("bankServiceUrl", gsrtBankServiceInfo.getBankServiceUrl());
		}	
		hql.append("and g.bankServiceState=:bankServiceState");
		paramMap.put("bankServiceState", BankServiceState.OPENED.value);
		return (GsrtBankServiceInfo) (gsrtBankServiceInfoDao.findByHql(hql.toString(), paramMap).size() > 0
				? gsrtBankServiceInfoDao.findByHql(hql.toString(), paramMap).get(0) : null);
	}
	
}
